/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 *
 * @author: jin Chen 
 * @date: Dec 5, 2003$
 * @version: 1.0
 */
package edu.psu.geovista.app.pcp.toolkits.time;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeUtil {
    public static final boolean DEBUG=false;
    public static Date getCurrentTime(){
        Date date=Calendar.getInstance().getTime();
        return date;
    }
    public static String getCurrentTimeString(){
        Date date=getCurrentTime();
        return convertDateToString(date);
    }
    /**
     * The string can be format to date again
     * @return
     */
    public static String convertDateToString(Date date){
        DateFormat fmt=new SimpleDateFormat();
        String dateSt=fmt.format(date);
        if(DEBUG)        {
        try {
            Date d2=fmt.parse(dateSt);
        } catch (ParseException e) {
            e.printStackTrace();  //To change body of catch statement use Options | File Templates.
        }
        }
        return dateSt;

    }
     public static Date convertStringToDate(String time){
          Date date=null;
          DateFormat fmt=new SimpleDateFormat();
          try {

                date=fmt.parse(time);// 

                } catch (ParseException e) {
                    e.printStackTrace();  //To change body of catch statement use Options | File Templates.
                }
        return date;
    }
}
